<template>
	<label :class="['ant-checkbox-wrapper', modelValue && 'ant-checkbox-wrapper-checked']">
		<span :class="['ant-checkbox', modelValue && 'ant-checkbox-checked']">
			<input
				type="checkbox"
				class="ant-checkbox-input"
				:value="modelValue"
				@input="handleInput($event)"
			/>
			<span class="ant-checkbox-inner"></span>
		</span>
		<span><slot></slot></span>
	</label>
</template>

<script setup lang="ts">
interface Props {
	modelValue: boolean
}

interface Emits {
	(e: 'update:modelValue', value: boolean): void
}

defineProps<Props>()
const emits = defineEmits<Emits>()

const handleInput = event => {
	emits('update:modelValue', event.target.checked)
}
</script>

<style lang="less" scoped>
.ant-checkbox-wrapper {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
	color: #000000d9;
	font-size: 14px;
	font-variant: tabular-nums;
	line-height: 1.5715;
	list-style: none;
	font-feature-settings: 'tnum';
	display: inline-flex;
	align-items: baseline;
	line-height: unset;
	cursor: pointer;
}

.ant-checkbox {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
	color: #000000d9;
	font-size: 14px;
	font-variant: tabular-nums;
	line-height: 1.5715;
	list-style: none;
	font-feature-settings: 'tnum';
	position: relative;
	top: 0.2em;
	line-height: 1;
	white-space: nowrap;
	outline: none;
	cursor: pointer;
}

.ant-checkbox-input {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: 1;
	width: 100%;
	height: 100%;
	cursor: pointer;
	opacity: 0;
}

.ant-checkbox-inner {
	position: relative;
	top: 0;
	left: 0;
	display: block;
	width: 16px;
	height: 16px;
	direction: ltr;
	background-color: #fff;
	border: 1px solid #d9d9d9;
	border-radius: 2px;
	border-collapse: separate;
	transition: all 0.3s;
}

.ant-checkbox-checked .ant-checkbox-inner {
	background-color: var(--main-color);
	border-color: var(--main-color);
}

.ant-checkbox-inner:after {
	position: absolute;
	top: 50%;
	left: 19%;
	display: table;
	width: 4.71428571px;
	height: 8.14285714px;
	border: 2px solid #fff;
	border-top: 0;
	border-left: 0;
	transform: rotate(45deg) scale(0) translate(-50%, -50%);
	opacity: 0;
	transition:
		all 0.1s cubic-bezier(0.71, -0.46, 0.88, 0.6),
		opacity 0.1s;
	content: ' ';
}

.ant-checkbox-checked .ant-checkbox-inner:after {
	position: absolute;
	display: table;
	border: 2px solid #fff;
	border-top: 0;
	border-left: 0;
	transform: rotate(45deg) scale(1) translate(-50%, -50%);
	opacity: 1;
	transition: all 0.2s cubic-bezier(0.12, 0.4, 0.29, 1.46) 0.1s;
	content: ' ';
}
.ant-checkbox + span {
	padding-right: 8px;
	padding-left: 8px;
}

@keyframes antCheckboxEffect {
	0% {
		transform: scale(1);
		opacity: 0.5;
	}

	to {
		transform: scale(1.2);
		opacity: 0;
	}
}

.ant-checkbox-checked:after {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	border: 1px solid var(--main-color);
	border-radius: 2px;
	visibility: hidden;
	animation: antCheckboxEffect 0.36s ease-in-out;
	animation-fill-mode: backwards;
	content: '';
}
</style>
